import { getOfficeAll, getOfficeList, getOffice, getOfficeTree, delOffice, saveOffice, updateOffice } from '@/api/sys/dept'

const actions = {
  
   // 获取启用的部门列表
   getOfficeAll({ commit }) {
    return new Promise((resolve, reject) => {
      getOfficeAll().then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  // 获取部门列表
  getOfficeList({ commit }, param) {
    return new Promise((resolve, reject) => {
      getOfficeList(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getOfficeTree({ commit }, param) {
    return new Promise((resolve, reject) => {
      getOfficeTree(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getOffice({ commit }, id) {
    return new Promise((resolve, reject) => {
      getOffice(id).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  updateOffice({ commit }, param) {
    return new Promise((resolve, reject) => {
      updateOffice(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**
   * 保存菜单
   * @param {菜单} data
   */
  saveOffice({ commit }, param) {
    return new Promise((resolve, reject) => {
      saveOffice(param).then(response => {
        const { data } = response
        resolve(data)
      }).catch(error => {
        reject(error)
      })
    })
  },

  /**
   *  删除菜单
   * @param {id} id
   */
  delOffice({ commit }, id) {
    return new Promise((resolve, reject) => {
      delOffice(id).then(res => {
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }

}

export default {
  namespaced: true,
  actions
}
